<?php
class Campus extends AppModel{
	var $name = "Campus";
	var $validate = array(
                'name'=>array(
                    'rule' => 'isUnique',
                    'message' => ''
                ),
	);
	
	var $belongsTo = array(
		'School' => array(
			'className' => 'School',
			'foreignKey' => 'school_id'
		)
	);
	
	/*
	 * 
	 * @param $lat 
	 * @param $lng 
	 * @param $scale  
	 */
	function findNeighbor($lat, $lng, $scale = 1.0){
		$northLat = floatval($lat) + 0.01 * $scale;
		$southLat = floatval($lat) - 0.01 * $scale;
		$eastLng = floatval($lng) + 0.01 * $scale;
		$westLng = floatval($lng) - 0.01 * $scale;
		$neighbors = $this->find('all',array('conditions' => array(
														'Campus.lat between ? and ?' => array($southLat, $northLat), 
														'Campus.lng between ? and ?' => array($westLng, $eastLng)
													)
												)
										);
		//pr($neighbors);
		return $neighbors;
	}
	
}
?>